-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor ASTTransformer.visit_For and fix a bug on grouped ndrange loops #648
Conversation
It gives me |
python/taichi/lang/transformer.py
Outdated
loop_body = t_loop.body | ||
inner_loop_body = loop_body[1].body | ||
inner_loop_body[1].body[0].value = self.parse_expr( | ||
'__I // __ndrange.acc_dimensions[__grouped_I + 1]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using self.parse_expr
to avoid the Expr
index in the template string but it didn't work.
python/taichi/lang/transformer.py
Outdated
loop_body += node.body | ||
|
||
node = ast.copy_location(t, node) | ||
return self.visit(node) # further translate as a range for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here self.visit
will further translate __grouped_I_tmp = 0
into __grouped_I_tmp = ti.expr_init(0)
and you get an expr. The solution is to first visit the node body, and then do your own transform so that what you write is what you end up with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After visiting the node body (translating as a range for), how can I locate the statements I want to modify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An easier way: see the trick here and protect your statements with ti.static(1)
so that it won't get further translated
taichi/python/taichi/lang/transformer.py
Line 340 in 063542f
if ti.static(1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, to be clear: try __grouped_I_tmp = ti.static(0)
so that this statement won't get transformed into __grouped_I_tmp = ti.expr_init(0)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After visiting the node body (translating as a range for), how can I locate the statements I want to modify?
In my understanding, the only transform you have to do here is to prepend some statements to the loop body so that you can get something like I
. You don't need to modify any existing statements in the old loop body.
An easy way to debug this is to enable |
I need However, As the error says, list indices are not allowed to be Maybe I should make use of |
Sure. |
|
|
# Conflicts: # python/taichi/lang/transformer.py
Ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Now visit_For
is much easier to read. Note that currently visit_For
is still a huge function. It would be good to move its components outside. For example, get_decorator
and visit_static_for
should be (static) member functions, at the same level of visit_For
itself.
This means you might have to pass a few originally automatically captured variables (e.g. node
) as member function parameters, but doing so will further clarify this function. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! This is really well done. I like your TaichiSyntaxError
treatments.
I'll merge once CI passes. Let me know when you are ready to chat about the next task.
Related issue id = #631
Also make mgpcg_advanced.py able to run with
self.dim = 2
.[Click here for the format server]